<?php
if(isset($_POST['action']))
{
    $db = new Database;
    // User Info
        $auth = Auth::getAuth('current_user');
        $user_id = $auth['id'];
        $company_id =  $auth['company_id'];
        $user_group = $auth['role'];
        $user_groupType = $auth['role_type'];
        $userPositionID = $auth['position_id'];
        $getPosition = $db->query("SELECT * FROM tbposition where id = '$userPositionID'","row");
        
    $page = $_POST['page'];
    $cur_page = $page;
    $page -= 1;
    $per_page = 10; // Per page
    $previous_btn = true;
    $next_btn = true;
    $first_btn = true;
    $last_btn = true;
    $start = $page * $per_page;
    $action = $_POST['action'];
    
    // For Sorting
    /*
        $dataSortValue = $_POST['dataSortValue'];
        if(!empty($dataSortValue)){
            if($_POST['counterSort']%2==0){
                $sort = "ORDER BY date DESC";
            }else{
                $sort = "ORDER BY date ASC";
            }
        }else{
            $sort = "ORDER BY form_title";
        }
    */
    if($action=="ActionStatus")
    {
	$queryRequest = $db->query("SELECT * from tbbuttons WHERE company_id = '$company_id'  and is_active = 1 $sort LIMIT $start, $per_page","array");
        $count = $db->query("SELECT * from tbbuttons WHERE company_id = '$company_id'  and is_active = 1","numrows");
        $no_of_paginations = ceil($count / $per_page);
    }
    $page = $page+1;
    $finaldata.= '<table class="table_data">
		    <thead>
			<tr>
			    <th>#</th>
			    <th>Status</th>
			    <th colspan="2">Actions</th>
			</tr>
		    </thead>';
    $finaldata.= '<tbody">';
    
    if($count>0){
        $ctr =1;
        foreach($queryRequest as $dataPositionList){
            $finaldata.= '   
            <tr id="row_button_'.$dataPositionList['id'].'">
		<td style="text-align:center">'.$ctr++.'</td>
		<td style="text-align:center">
		<input type="textbox" class="input-normal display" id="editTXT_button_'.$dataPositionList['id'].'" value="'.$dataPositionList['button'].'" >
		<span id="editSpan_button_'.$dataPositionList['id'].'">'.$dataPositionList['button'].'</span>
		</td>
		<td style="text-align: center">
		    <a class="editAdmin edit_button" id="edit_button_'.$dataPositionList['id'].'" rel="button" style="cursor: pointer"><li class="icon-edit"></li></a>
		    <a class="editAdmin editCancel display" id="editCancel_button_'.$dataPositionList['id'].'" rel="button" style="cursor: pointer"><li class="icon-remove"></li></a>
		    <a class="editAdmin editOk display" id="editOk_button_'.$dataPositionList['id'].'" rel="button" style="cursor: pointer"><li class="icon-ok"></li></a>
		</td>
		<td style="text-align: center"><a class="deleteAdmin delete_button" id="delete_button_'.$dataPositionList['id'].'" rel="button" style="cursor: pointer"><li class="icon-trash"></li></a></td>
	    </tr>';
	    
	}
        //pagination
        pagination($cur_page,$page,$per_page,$start,$previous_btn,$next_btn,$first_btn,$last_btn,$no_of_paginations,$finaldata,$count,$action,$value);
    }else{
        $finaldata.='<tr><td colspan="3"><center>No Record Found</center></td></tr>';
        echo $finaldata;
    }
    
}
?>
<script>
    $(".actionUserRequest").tooltip();
</script>
